
LoginWindow = Ext.extend(Ext.Window, {
	renderTo : 'loginWin',
	title : '登录系统',
	width : (mainPanelWidth*4/5)/3.9,
	height : mainPanelHeight/6.25,
	closable : false,
	draggable : false,
	resizable : false,
	defaults : {
		border : false
	},
	buttonAlign : 'center',
	createFormPanel : function() {
		return new Ext.form.FormPanel({
			bodyStyle : 'padding-top:6px',
			defaultType : 'textfield',
			labelAlign : 'right',
			labelWidth : 55,
			labelPad : 0,
			frame : true,
	    	keys:[{  
		        key:Ext.EventObject.ENTER,   
		        fn:function(){
					if(this.fp.form.isValid()) {
						this.fp.form.submit({
							waitTitle : '请稍候',
							waitMsg : '正在登录......',
							url : basepath+'/auth/login.html',
							success : function(form, action) {
								window.location.href =basepath+'/login/wait.jsp';	
							},
							failure : function(form, action) {
								var m =Ext.decode(action.response.responseText);
								Ext.MessageBox.alert("错误",m.error,function(){
									form.reset();
									Ext.get('loginID').focus();
								});
							}
						});
					}        
		        },   
		        scope:this  
	  		}],			
			defaults : {
				allowBlank : false,
				width : (mainPanelWidth*4/5)/3.7*1/2
			},
			items : [{
				cls : 'user',
				name : 'loginID',
				fieldLabel : '帐号',
				blankText : '帐号不能为空',
				 maxLength:16,
				 minLength:4  
			}, {
				cls : 'key',
				id:'pwd',
				name : 'password',
				fieldLabel : '密码',
				blankText : '密码不能为空',
				inputType : 'password',
				maxLength:16,
				 minLength:6 
			}]
		});
	},
	login : function() {
		if (this.fp.form.isValid()) {
			this.fp.form.submit({
				waitTitle : '请稍候',
				waitMsg : '正在登录......',
				url : basepath+'/crm/crmlogin/login.html',
				success : function(form, action) {
					window.location.href =basepath+'/login/wait.jsp';				
				},
				failure : function(form, action) {
					var m =Ext.decode(action.response.responseText);
					Ext.MessageBox.alert("错误",m.error,function(){
						//form.reset();
						Ext.getCmp('pwd').setValue('');
						//Ext.get('loginID').focus();
						//Ext.get('loginID').selectText(0);
						document.getElementById('loginID').select();
					});
				}
			});
		}
	},
	initComponent : function() {
		LoginWindow.superclass.initComponent.call(this);
		this.fp = this.createFormPanel();
		this.add(this.fp);
		this.addButton('登录', this.login, this);
		this.addButton('重置', function() {
			this.fp.form.reset();
		}, this);
	}
});

Ext.onReady(function() {
Ext.BLANK_IMAGE_URL =basepath+'/ext/resources/images/vista/s.gif';
Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'qtip';
	var win = new LoginWindow();	
	win.show();
});